package alertimport ()// ConditionEvaluator represents an option that can be used to configure a condition.typeConditionEvaluatorfunc(condition *condition)// QueryReducer represents a function used to reduce a query to a single value// that can then be fed to the evaluator to determine if the alert will be// triggered or not.typeQueryReducerstringconst (// Avg defines the query to execute and computes the average of the results. // See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-exampleAvgQueryReducer = "avg"// Sum defines the query to execute and computes the sum of the results. // See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-exampleSumQueryReducer = "sum"// Count defines the query to execute and counts the results. // See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-exampleCountQueryReducer = "count"// Last defines the query to execute and takes the last result. // See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-exampleLastQueryReducer = "last"// Min defines the query to execute and takes the smallest result. // See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-exampleMinQueryReducer = "min"// Max defines the query to execute and takes the largest result. // See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-exampleMaxQueryReducer = "max"// Median defines the query to execute and computes the mediam of the results. // See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-exampleMedianQueryReducer = "median"// Diff defines the query to execute. // See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-exampleDiffQueryReducer = "diff"// PercentDiff defines the query to execute. // See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-examplePercentDiffQueryReducer = "percent_diff")// Operator represents a logical operator used to chain conditions.typeOperatorstring// And chains conditions with a logical ANDconstAndOperator = "and"// Or chains conditions with a logical ORconstOrOperator = "or"type condition struct { builder *sdk.AlertCondition}func newCondition( QueryReducer, string, ConditionEvaluator) *condition { := &condition{builder: &sdk.AlertCondition{Type: "query",Query: sdk.AlertConditionQueryRef{Params: []string{}},Reducer: sdk.AlertReducer{Type: string(), Params: []string{}}, }, } ()return}// HasNoValue will match queries returning no value.func () ConditionEvaluator {returnfunc( *condition) { .builder.Evaluator = sdk.AlertEvaluator{Type: "no_value", Params: []float64{}} }}// IsAbove will match queries returning a value above the given threshold.func ( float64) ConditionEvaluator {returnfunc( *condition) { .builder.Evaluator = sdk.AlertEvaluator{Type: "gt", Params: []float64{}} }}// IsBelow will match queries returning a value below the given threshold.func ( float64) ConditionEvaluator {returnfunc( *condition) { .builder.Evaluator = sdk.AlertEvaluator{Type: "lt", Params: []float64{}} }}// IsOutsideRange will match queries returning a value outside the given range.func ( float64, float64) ConditionEvaluator {returnfunc( *condition) { .builder.Evaluator = sdk.AlertEvaluator{Type: "outside_range", Params: []float64{, }} }}// IsWithinRange will match queries returning a value within the given range.func ( float64, float64) ConditionEvaluator {returnfunc( *condition) { .builder.Evaluator = sdk.AlertEvaluator{Type: "within_range", Params: []float64{, }} }}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.